<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/5/16
 * Time: 17:03
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\common\lib;

class Str
{
    public static function guid(): string
    {
        if (function_exists('com_create_guid')) {
            return com_create_guid();
        } else {
            mt_srand((int)microtime());
            $charid = strtoupper(md5(uniqid((string)rand(), true)));
            $hyphen = chr(45);
            $uuid = substr($charid, 0, 8) . $hyphen
                . substr($charid, 8, 4) . $hyphen
                . substr($charid, 12, 4) . $hyphen
                . substr($charid, 16, 4) . $hyphen
                . substr($charid, 20, 8);
            return $uuid;
        }
    }

    /**
     * 判断是否是特殊字符 eg：emoji表情
     * @param string $str  待判断字符串
     * @return bool 判断结果
     */
    public static function has_special_char(string $str="")
    {
        $len = mb_strlen($str);
        $array = [];
        for ($i = 0; $i < $len; $i++) {
            $array[] = mb_substr($str, $i, 1, 'utf-8');
            if (strlen($array[$i]) >= 4) {
                return true;
            }
        }
        return false;
    }
}